package com.j.lemon.learn.fastjson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @Author lijunjun
 * @Date 2020-07-13 16:56
 * @Description
 */
public class MainTest {
    public static void main(String[] args) throws IOException {
//        Store store = new Store();
//        store.setName("Hollis");
//        Apple apple = new Apple();
//        apple.setPrice(new BigDecimal(0.5));
//        store.setFruit(apple);
//        String jsonString = JSON.toJSONString(store, SerializerFeature.WriteClassName);
//        System.out.println("toJSONString : " + jsonString);
//
//        Store newStore = JSON.parseObject(jsonString, Store.class);
//        System.out.println("parseObject : " + newStore);
//        Apple newApple = (Apple) newStore.getFruit();
//        System.out.println("getFruit : " + newApple);

        FileChannel fileChannel = new FileOutputStream("/Users/lijunjun/Desktop/text.txt",true).getChannel();
        StringBuffer stringBuffer = new StringBuffer();
        Charset utf8 = Charset.forName("UTF8");
        String s = null;
        stringBuffer.append(s);
        fileChannel.write(utf8.encode(stringBuffer.toString()));
        stringBuffer.delete(0,stringBuffer.length());
//        for (int i = 0; i < 1000000; i++) {
//            stringBuffer.append("this is the test text ").append(i);
//            fileChannel.write(utf8.encode(stringBuffer.toString()));
//            stringBuffer.delete(0,stringBuffer.length());
//        }

//        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
//        stringBuffer.delete(0,1);
//        stringBuffer.append("\r\n");
//        fileChannel.write(Charset.forName("utf-8").encode(stringBuffer.toString()));

//        CharBuffer wrap = CharBuffer.wrap("123");
//        int remaining = wrap.remaining();
//        System.out.println(remaining);


    }
}
